package com.chenyi.web.controller.monitor;

import com.chenyi.common.annotation.Log;
import com.chenyi.common.core.controller.BaseController;
import com.chenyi.common.core.page.TableDataInfo;
import com.chenyi.common.enums.BusinessType;
import com.chenyi.common.utils.poi.ExcelUtil;
import com.chenyi.system.domain.SysAdminLogin;
import com.chenyi.system.service.ISysAdminLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统访问记录
 * 
 * @author wangkh
 */
@RestController
@RequestMapping("/admin/monitor/adminLoginInfo")
public class AdminLoginInfoController extends BaseController
{
    @Autowired
    private ISysAdminLoginService logininforService;

    @PreAuthorize("@admin.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public ResponseEntity<TableDataInfo> list(SysAdminLogin logininfor)
    {
        startPage();
        List<SysAdminLogin> list = logininforService.selectAdminLoginList(logininfor);
        return new ResponseEntity<>(getDataTable(list), HttpStatus.OK);
    }

    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@admin.hasPermi('monitor:logininfor:export')")
    @GetMapping("/export")
    public ResponseEntity<Object> export(SysAdminLogin logininfor)
    {
        List<SysAdminLogin> list = logininforService.selectAdminLoginList(logininfor);
        ExcelUtil<SysAdminLogin> util = new ExcelUtil<SysAdminLogin>(SysAdminLogin.class);
        return util.exportExcel(list, "登录日志");
    }

    @PreAuthorize("@admin.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public ResponseEntity<Object> remove(@PathVariable Long[] infoIds)
    {
        return ResponseEntity.ok(logininforService.deleteAdminLoginByIds(infoIds));
    }

    @PreAuthorize("@admin.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public ResponseEntity<Object> clean()
    {
        logininforService.cleanAdminLogin();
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
